<?php
require_once APPLICATION_PATH.'\misc\exceptionHandler.php';
require_once APPLICATION_PATH.'\misc\sessionController.php';
require_once APPLICATION_PATH.'\misc\exceptionHandler.php';
class SettingController extends Zend_Controller_Action
{
    private $paramName=array('Super');
    private $classname='SettingController.php';
    public function init()
    {   $sessionController=new sessionController();
        $this->view->sessioncontroller = $sessionController;
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function listAction()
    {

        
         try{
        $sessionController=new sessionController();

        if($sessionController->checkSessionAdmin($this->paramName)){
            $setting = new Application_Model_DbTable_Settings();
            $this->view->setting=$setting->fetchAll();
         }else{
                        $this->_helper->redirector('login','admin');
                    }

        }catch(Zend_Exception $e){
           //initialize exceptionHandler
           $exceptionHandler = new exceptionHandler();
           $exceptionHandler->addLog($e, $this->classname);



    }
    }

    public function editAction()
    {
        $email = new Zend_Form_Element_Text("email");
        $email->setLabel("Email")
             ->setRequired("true")
             ->addFilter("StripTags")
             ->addFilter("StringTrim")
             ->addValidators(array('EmailAddress'=>'EmailAddress'))
             ->addErrorMessages(array('EmailAddress'=>'Format email anda salah'))
             ->setAttrib("maxLength","100");
        try{
        $sessionController=new sessionController();
        if($sessionController->checkSessionAdmin($this->paramName)){
            $id=$this->_getParam('id',0);
            $array=array();
            $setting = new Application_Model_DbTable_Settings();
            $settings=$setting->fetchRow('id='.(int)$id);
            $id=$this->_getParam('id',0);

            $element = new Zend_Form_Element_Text('element');
            $element->setLabel($settings['param'])
                    ->setValue($settings['value']);
            $submit=new Zend_Form_Element_Submit("submit");
            $submit->setAttrib("id","submit");
            $submit->setLabel('Ubah');
            $formDisplay=new Application_Form_Display();
            $formDisplay->addElements(array($element,$submit));
            $this->view->form=$formDisplay;
            if($this->getRequest()->isPost()){
            $postData = $this->getRequest()->getPost();
            //Validate input data
            if($formDisplay->isValid($postData)){
               $data=array('value'=>$formDisplay->getValue('element'));
               $setting->update($data, 'id='.(int)$id);

               
               $this->_helper->redirector('list');
            }else{
                $formDisplay->populate($postData);
            }
        }
        
         }else{
                        $this->_helper->redirector('login','admin');
                    }


        }catch(Zend_Exception $e){
           //initialize exceptionHandler
           $exceptionHandler = new exceptionHandler();
           $exceptionHandler->addLog($e, $this->classname);



    }
    }


}





